package com.mmx;


import com.mmx.config.MmxDatabaseConfig;
import lombok.extern.slf4j.Slf4j;


import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;


/**
 * @desc: 自动注入配置
 * @author: liushuai
 * @date: 2023/1/21 11:24
 */
@Slf4j
@Configuration
@ComponentScan("com.mmx")
@MapperScan(basePackages={"com.mmx.mapper"})
@EnableConfigurationProperties({MmxDatabaseConfig.class})
public class MmxAutoConfiguration {

    /**
     * DatabaseIdProvider元素主要是为了支持不同的数据库
     * @param
     * @return: org.apache.ibatis.mapping.DatabaseIdProvider
     * @Author: liushuai
     * @Date: 2023/1/31 11:42
     */
    @Bean
    public DatabaseIdProvider getDatabaseIdProvider() {
        DatabaseIdProvider databaseIdProvider = new VendorDatabaseIdProvider();
        Properties properties = new Properties();
        properties.setProperty("PostgreSQL", "postgresql");
        properties.setProperty("MySQL", "mysql");
        databaseIdProvider.setProperties(properties);
        return databaseIdProvider;
    }

}
